package com.vint.basic;

/**
 * Copyright (C) 2017, Xiaomi Inc. All rights reserved.
 * Created by vint @ 2017/10/29.
 * in leetcode
 */
public class MathUtil {
	//判断是否为质数
	public static boolean isPrime1(int n){
		if(n<2)return false;
		for(int i=2;i*i<=n;i++){
			if(n%i==0)return false;
		}
		return true;
	}

	//计算平方根，牛顿迭代
	public static double sqrt(double c){
		if(c<0)return Double.NaN;
		double err = 1e-15;
		double t = c;
		while (Math.abs(t-c/t)>err*t){
			t = (c/t + t)/2.0;
		}
		return t;
	}
	public static void main(String[] args) {

	}
}
